//
//  L_PlayView.m
//  音悦咖
//
//  Created by dllo on 15/7/17.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "L_PlayView.h"
#import "L_Singleton.h"
#import "STKAudioPlayer.h"
#define myWidth self.frame.size.width
#define myHeight self.frame.size.height

@interface L_PlayView ()



@end

@implementation L_PlayView

- (void)dealloc
{
    [_title release];
    [_backButton release];
    [_backImage release];
    [_showImage release];
    [_backgroundScroll release];
    [_songerPicView release];
    [_lyricView release];
    [_play release];
    [_upSong release];
    [_nextSong release];
    [_playPattern release];
    [_progressSlider release];
    [_playTime release];
    [_surplusTime release];
    [_songName release];
    [_songerName release];
    [_playList release];
    [_scrollView release];
    [super dealloc];
}


#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}

#pragma mark - 创建视图
- (void)createView
{
    // 返回按钮
    self.backButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 30, 30, 30)];
    [self.backButton setImage:[UIImage imageNamed:@"backbutton.png"] forState:UIControlStateNormal];
    [self addSubview:self.backButton];
    //背景
    tempImage = [[UIImageView alloc] initWithFrame:self.bounds
                 ];
    tempImage.userInteractionEnabled = YES;
    tempImage.image = [UIImage imageNamed:@"88.jpg"];
    [self addSubview:tempImage];
    [tempImage release];
    
    // 返回按钮
    self.backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, myWidth / 8, myHeight / 8)];
    [self.backButton setImage:[UIImage imageNamed:@"back@2x.png"] forState:UIControlStateNormal];
    [tempImage addSubview:self.backButton];
    [_backButton release];
    
    // 标题
    self.title = [[UILabel alloc] initWithFrame:CGRectMake(myWidth / 8, 20, myWidth - myWidth / 8 * 2, myHeight / 10 / 2)];
    _title.font = [UIFont boldSystemFontOfSize:20];
    _title.textColor = [UIColor whiteColor];
    [tempImage addSubview:_title];
    [_title release];
    
    // 歌手名
    self.songerName = [[UILabel alloc] initWithFrame:CGRectMake(myWidth / 8, 20 + myHeight / 10 / 2, myWidth - myWidth / 8 * 2, myHeight / 10 / 2)];
    self.songerName.font = [UIFont systemFontOfSize:15];
    self.songerName.textColor = [UIColor whiteColor];
    [tempImage addSubview:self.songerName];
    [_songerName release];
    
    
    // 创建scrollView
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20 + myHeight / 10, myWidth, myHeight * 0.7)];
    self.scrollView.pagingEnabled = YES;
    self.scrollView.contentSize = CGSizeMake(myWidth * 2, myHeight * 0.7);
    self.scrollView.showsHorizontalScrollIndicator = NO;
    [self addSubview:self.scrollView];
    [_scrollView release];
  
    
    
    // 背景图片
    self.backImage = [[UIImageView alloc] initWithFrame:CGRectMake(myWidth, 0, myWidth, myHeight * 0.7)];
    
    [self.scrollView addSubview:_backImage];
    [_backImage release];
    _backImage.alpha = 0.8;
    
    
    // 播放图片
    self.showImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, myWidth / 1.5, myWidth / 1.5)];
    self.showImage.layer.cornerRadius = myWidth / 1.5 / 2;
    self.showImage.layer.masksToBounds = YES;
    self.showImage.center = CGPointMake(myWidth / 2, myHeight  / 2.5);
    [self.scrollView addSubview:self.showImage];
    [_showImage release];
    
    //创建slider
    self.progressSlider = [[UISlider alloc] initWithFrame:CGRectMake(myWidth / 6, myHeight / 6 * 5, myWidth / 6 * 4, myWidth / 6 * 0.5)];
    [self.progressSlider setThumbImage:[UIImage imageNamed:@"sliderImg"] forState:UIControlStateNormal];
    self.progressSlider.maximumTrackTintColor = [UIColor whiteColor];
    [self addSubview:self.progressSlider];
    [_progressSlider release];
    [self.progressSlider addTarget:self action:@selector(progressSliderAction) forControlEvents:UIControlEventValueChanged];
    
    // 播放时间/剩余时间
    self.playTime = [[UILabel alloc] initWithFrame:CGRectMake(myWidth / 6 - 50, myHeight / 6 * 5 - 5, 50, 40)];
    self.playTime.textAlignment = NSTextAlignmentCenter;
    self.playTime.textColor = [UIColor whiteColor];
    self.surplusTime = [[UILabel alloc] initWithFrame:CGRectMake(self.progressSlider.frame.origin.x + self.progressSlider.frame.size.width, myHeight / 6 * 5 - 5, 50, 40)];
    self.surplusTime.textAlignment = NSTextAlignmentCenter;
    self.surplusTime.textColor = [UIColor whiteColor];
    [self addSubview:_playTime];
    [self addSubview:_surplusTime];
    [_playTime release];
    [_surplusTime release];
    
    // 播放按钮
    self.play = [[UIButton alloc] initWithFrame:CGRectMake(myWidth / 2 - 15, myHeight / 4 * 3.7, 35, 35)];
    [self addSubview:self.play];
    [_play release];
    
    // 上一首按钮
    self.upSong = [[UIButton alloc] initWithFrame:CGRectMake(myWidth * 0.25, myHeight / 4 * 3.7, 30, 30)];
    [self addSubview:self.upSong];
    [_upSong release];
    
    // 下一首按钮
    self.nextSong = [[UIButton alloc] initWithFrame:CGRectMake(myWidth * 0.65, myHeight / 4 * 3.7, 30, 30)];
    [self addSubview:self.nextSong];
    [_nextSong release];
    
    // 播放模式按钮
    self.playPattern = [[UIButton alloc] initWithFrame:CGRectMake(20, myHeight / 4 * 3.7, 30, 30)];
    [self addSubview:self.playPattern];
    [_playPattern release];
    
    // 播放列表按钮
    self.playList = [[UIButton alloc] initWithFrame:CGRectMake(myWidth - 50, myHeight / 4 * 3.7, 30, 30)];
    [self addSubview:self.playList];
    [_playList release];
    
    
    
}

#pragma mark - 进程方法
- (void)progressSliderAction
{
    L_Singleton *single = [L_Singleton shareManager];
    [single.streamer seekToTime:self.progressSlider.value * single.streamer.duration];

 
}



@end
